<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/classes/DBHelper.class.jsp"%>
<%@ include file="/classes/ConstantUtil.class.jsp" %>
<%@ include file="/classes/CommonHelper.class.jsp" %>
<%@ include file="/common/basePath.jsp" %>
<%
//判断登录
if(null==session.getAttribute(SESSION_USER)){
	// 前往登录页
	String url = request.getRequestURL().toString();
// 	url = url.replace("app//","app/"); 
// 	if (request.getQueryString() != null) {
// 		url += "?" + request.getQueryString();
// 	}
	url = basePath+"ldxx/ldxx_save.jsp?"+request.getQueryString();
	
	url = URLEncoder.encode(url,"UTF-8");
// 	System.out.println(basePath+"ldxx/login_user.jsp?go_url=" + url);
	response.sendRedirect(basePath+"ldxx/login_user.jsp?go_url=" + url);
	return;	
}
//获取操作类型
String operateTypeId = getParameterAndSetAttribute(request,"operateTypeId");
//获取部门ID
String authDepart = getParameterAndSetAttribute(request,"authDepart");

//执行特殊操作
if(nullOrEmpty(operateTypeId)){
	out.print("错误的连接！");
	return;	
}
//网上信访
// if("7e83044130a048caa3a3bf725d54a63e".equals(operateTypeId)){
// 	authDepart = "7e83044130a048caa3a3bf725d54a63e";
// }
//书记信箱
if("7e83044130a048caa3a3bf725d54a63g".equals(operateTypeId)){
	authDepart = "2d9fde2242c144f6998739f5e3b19907";
}
//县长信息
if("7e83044130a048caa3a3bf725d54a63b".equals(operateTypeId)){
	authDepart = "c52743ea61434f60ba0cd11ce8de6d67";
}
//12345网络信件
if("7e83044130a048caa3a3bf725d54a63h".equals(operateTypeId)){
	authDepart = "38056ec4e11740d2aa09a8353c33ce2c";
}
pageContext.setAttribute("authDepart",authDepart);


%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>民意征集-后台新增</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"></meta>
<link href="css/webcss1.css" rel="stylesheet" type="text/css" id="cssys"></link>
<script type="text/javascript" src="../js/jquery-1.7.min.js"></script>
<script type="text/javascript" src="../js/jquery.form.js"></script>
<script src="../js/artDialog/artDialog.js?skin=default"></script>
<script type="text/javascript">

$(document).ready(function() { 
//     $('#addForm').ajaxForm(function(data) {
//     	eval(data);
//     });
 	var options = {
       // target:        '#output1',   // target element(s) to be updated with server response
        beforeSubmit:  toSubmit,  // pre-submit callback
        success:       showResponse,  // post-submit callback

        // other available options:
        //url:       url         // override for form's 'action' attribute
        //type:      type        // 'get' or 'post', override for form's 'method' attribute
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type)
        //clearForm: true        // clear all form fields after successful submit
        //resetForm: true        // reset the form after successful submit

        // $.ajax options can be used here too, for example:
        timeout:   3000,
        error:	errorFun
    };
    $('#addForm').ajaxForm(options);
}); 
function errorFun(){
	
}
function showResponse(responseText, statusText)  {
    // for normal html responses, the first argument to the success callback
    // is the XMLHttpRequest object's responseText property

    // if the ajaxForm method was passed an Options Object with the dataType
    // property set to 'xml' then the first argument to the success callback
    // is the XMLHttpRequest object's responseXML property

    // if the ajaxForm method was passed an Options Object with the dataType
    // property set to 'json' then the first argument to the success callback
    // is the json data object returned by the server
    $("#do_add").attr("disabled",false);
   toRefresh();
eval(responseText);
//     alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
//         '\n\nThe output div should have already been updated with the responseText.');
}

function toSubmit(){
	if(validateName()&&validatePhone()&&validateEmail()&&validateAddress()&&validateTitle()&&validateContent()&&validateCode()){
		$("#do_add").attr("disabled",true);
		return true;
	}else{
		return false;
	}
}

function validateName(){
	var messagerNameValue=$.trim($("#messager_name").val());
	if(messagerNameValue=='' || messagerNameValue.length>10){			
		$('#messagerName_d').css("display","inline");	
		return false;
	}else{	
		$('#messagerName_d').css("display","none");				
		return true;
	}
}

function validatePhone(){
	var messagerPhoneValue=$.trim($('#messager_phone').val());
	var reg=new RegExp(/^(1[358]\d{9})$|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/),
	result=reg.test(messagerPhoneValue);
	if(!result){
		$('#messagerPhone_d').css("display",'inline');
		return false;
	}else{
		$('#messagerPhone_d').css("display",'none');
		return true;
	}
}

function checkMail(email){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) {
			return true;
	}
	return false;
}
function validateEmail(){
	var messagerEmailValue=$.trim($('#messager_email').val());
	if (!checkMail(messagerEmailValue)){
		$('#messagerEmail_d').css("display",'inline');
		return false;
	}else{
		$('#messagerEmail_d').css("display",'none');
		return true;
	}
}
function validateAddress(){
	var messagerAddressValue=$.trim($('#messager_address').val());
	if (messagerAddressValue==''||messagerAddressValue.length>50){
		$('#messagerAddress_d').css("display",'inline');
		return false;
	}else{
		$('#messagerAddress_d').css("display",'none');
		return true;
	}
}

function validateTitle(){
	var titleValue=$.trim($('#title').val());	
	if(titleValue==''||titleValue.length>50){
		$('#title_d').css("display",'inline');
		return false;
	}else{
		$('#title_d').css("display",'none');
		return true;
	}
}
function validateContent(){
	var contentValue=$.trim($('#content').val());	
	if(contentValue==''||contentValue.length>4000){
		$('#content_d').css("display",'inline');
		return false;
	}else{
		$('#content_d').css("display",'none');
		return true;
	}
}

function validateCode(){
	var codeValue=$.trim($('#code').val());
	if(null!=codeValue && ""!=codeValue){
		return true;
	}else{
		alert("请输入验证码！");
		return false;
	}
}

function toRefresh(){	
	$("#verifyCode").attr("src","../imageMesg.jsp?r="+Math.random());;
}
</script>
</head>
<body>
<div style="width:730px; margin: auto; height:410px; overflow-x:hidden; overflow-y:auto; background:#FFF; border:0px solid #D6F1FB;">
	<form action="ldxx_save_do.class.jsp" method="post" onsubmit="return toSubmit();" id="addForm">
		<table border=0 cellpadding="0" cellspacing="0" class="comtable">
			<tr>
				<td width="130" class="comtable_td1" style="text-align: left;">姓名:</td>
				<td colspan="2" style="text-align: left;">
				<input type="text"	id="messager_name" name="messager_name" value="${session_user.true_name }" />
				<font color=red>*</font>
					<div style="position: relative; text-align: center; display: none;"
						id="messagerName_d">
						<font color=red>姓名为空，或长度超过10个英文字母或汉字</font>
					</div></td>
			</tr>
			<tr>
				<td style="text-align: left;" class="comtable_td1">性别:</td>
				<td colspan="2" style="text-align: left;">
					<input name="messager_sex" type="radio" checked="checked" value="1" />男 
					<input name="messager_sex" type="radio" value="0" /> 女
				</td>
			</tr>
			<tr>
				<td style="text-align: left;" class="comtable_td1">电话:</td>
				<td colspan="2" style="text-align: left;">
					<input type="text" name="messager_phone" id="messager_phone" onblur="validatePhone()"	value="${session_user.phone }" class="c b"/>
					<font color=red>*</font>
					<div
						style="position: relative; text-align: center; display: none;"
						id="messagerPhone_d">
						<font color=red>电话号码为空，或格式不正确;支持分机、长途座机、手机号码</font>
					</div>
				</td>
			</tr>
			<tr>
				<td style="text-align: left;" class="comtable_td1">电子邮箱</td>
				<td colspan="2" style="text-align: left;">
					<input type="text" name="messager_email" id="messager_email" onblur="validateEmail()" value="${session_user.email }" class="c b"/>
					<font color=red>*</font>
					<div
						style="position: relative; text-align: center; display: none;"
						id="messagerEmail_d">
						<font color=red>邮箱格式不正确;格式为xxx@xxx.xxx</font>
					</div>
				</td>

			</tr>
			<tr>
				<td style="text-align: left;" class="comtable_td1">常住地址:</td>
				<td colspan="2" style="text-align: left;">
				<input type="text" name="messager_address" id="messager_address" onblur="validateAddress()" value="" class="c b"/>
				<font color=red>*</font>
				<div style="position: relative; text-align: center; display: none;" id="messagerAddress_d">
					<font color=red>地址不能为空且不能超过50个汉字或英文字母</font>
				</div>
				</td>

			</tr>
			<tr>
				<td style="text-align: left;" class="comtable_td1">标题:</td>
				<td colspan="2" style="text-align: left;">
				<input type="text" name="title" id="title" onblur="validateTitle()" value="" class="c b"/>
				<font color=red>*</font>
				<div style="position: relative; text-align: center; display: none;" id="title_d">
					<font color=red>标题不能为空且不能超过50个汉字或英文字母</font>
				</div>
				</td>
			</tr>

			<tr>
				<td valign="top" style="text-align: left;" class="comtable_td1">留言内容:</td>
				<td colspan="2" style="text-align: left;">
				<textarea rows="9" name="content" id="content" class="c" onblur="validateContent()"></textarea>
				<font color=red>*</font>
					<div style="position: relative; text-align: center; display: none;" id="content_d">
						<font color=red>留言内容不得超过4000字符且不能为空</font>
					</div>
				</td>
			</tr>
			<tr style="display: none;">
				<td style="text-align: left;" class="comtable_td1">信息是否公开：</td>
				<td colspan="2" style="text-align: left;">
				<select name="is_public" style="width: 60px;" style="display: none;">
					<option value="1" >是</option>
					<option value="0" selected="selected">否</option>
				</select>
				</td>
			</tr>
			<tr>
				<td style="text-align: left;" class="comtable_td1">请输入验证码：</td>
				<td width="149" style="text-align: left;">
				<input id="code" name="code" style="width: 120px;" /> 
				<font color=red>*</font>
				<a href="javascript:toRefresh()">
				
				</a>
				</td>
				<td width="232" style="text-align: left;"><img id="verifyCode" src="../imageMesg.jsp" alt="点击刷新验证码" border="0"	 /></td>
			</tr>
			<tr>
				<td colspan="3" style=" padding-top:10px;text-align:center;">
				<%--操作类型 --%>
				<input type="hidden" name="operateTypeId" value="${operateTypeId }" style="width: 3px;" />
				<%-- 部门ID --%>
				<input type="hidden" name="authDepart" value="${authDepart }" />
				<input type="hidden" name="appUserId" value="${session_user.guid}"/><br />
                <input type="submit" id="do_add" name="do_add" value="提交" style="width:60px;"/>
                <input type="reset" value="重置" style="width:60px; margin-left:15px;"/>
				</td>
			</tr>
		</table>
	</form>
    </div>
</body>
</html>